<?php
/**
 * @version $Id: HelpScreenIncluder.php 28 2009-06-29 20:28:04Z der.el.kuku $
 * @package	HelpScreenIncluder
 * @author		Nikolai Plath (elkuku) {@link http://www.nik-it.de NiK-IT.de}
 * @author		Created on 09-Feb-2009
 *
 * Install:
 * Add
 * require_once( $IP.'/extensions/HelpScreenIncluder/HelpScreenIncluder.php' );
 * to your LocaleSettings.php
 *
 * Usage:
 * <HelpScreenIncluder>dummy</HelpScreenIncluder>
 * 
 * @todo how to make the parser recognize the <tag /> syntax ???
 * 
 * Required:
 * Have Fun =;)
 */

//--No direct access
defined('MEDIAWIKI') or die('=;)');

defined('DS') or define('DS', DIRECTORY_SEPARATOR);

//Avoid unstubbing $wgParser on setHook() too early on modern (1.12+) MW versions, as per r35980
if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) )
{
	$wgHooks['ParserFirstCallInit'][] = 'wfHelpScreenIncluder';
}
else
{ // Otherwise do things the old fashioned way
	$wgExtensionFunctions[] = 'wfHelpScreenIncluder';
}

$wgExtensionCredits['parserhook'][] = array(
	'version'     => '1.0',
	'name'        => 'HelpScreenIncluder',
	'author'      => array('Nikolai Plath'),
	'email'       => 'nik@',
	'url'         => 'http://www.mediawiki.org/wiki/Extension:HelpScreenIncluder...soon',
	'description' => 'adds <tt>&lt;fold&gt;</tt> tags',
);

function wfHelpScreenIncluder()
{
	global $wgParser, $wgHooks;
	$wgParser->setHook('HelpScreenIncluder', 'renderHelpScreenIncluder');
#	$wgHooks['OutputPageParserOutput'][] = 'fnFoldAwayOutputHook';

	return true;
}//function

function renderHelpScreenIncluder($input, $argv, &$parser)
{
	/*
	 * Array of defined wiki pages
	 * @todo auslagern
	 */
	$pages = array(
		'screen.config.15'
		, 'screen.banners.15'
	);
	
	$page = $_GET['page'];
	if( ! $page )
	{
		/*
		 * No page given
		 */
		return 'Diese Seite ist dazu gedacht, blabla..';
	}
	if( ! in_array($page, $pages))
	{
		/*
		 * Not found in pages array
		 */
		return 'Ungültige Seite - '.print_r($_REQUEST,true);
	}
	
	/*
	 * Write an {{:includepage}} tag
	 */
	return $parser->recursiveTagParse('{{:'.$page.'}}');
}//function

/**
 * Entry point for the hook for printing JS and CSS:
 * not used
 */
/*
function fnFoldAwayOutputHook( &$m_pageObj, $m_parserOutput ) {
	if( defined('FOLD_AWAY_ADDED'))
	{
		//--Only add once
		return true;
	}
	define ('FOLD_AWAY_ADDED', 1);
	global $wgScriptPath;

	//--CSS
	$m_pageObj->addLink(
		array(
	      'rel'   => 'stylesheet',
	      'type'  => 'text/css',
	      'href'  => $wgScriptPath.'/extensions/FoldAway/FoldAway.css'
		)
	);

	//--JS
	$m_pageObj->addScriptFile($wgScriptPath.DS.'extensions'.DS.'FoldAway'.DS.'FoldAway.js');

	# Be nice:
	return true;
}//function
*/
